home *** CD-ROM | disk | FTP | other *** search
- ===========================================================================
- BBS: The Abacus * HST/DS * Potterville MI
- Date: 05-10-93 (00:00) Number: 22
- From: BRAD GREEP Refer#: NONE
- To: MARK CORGAN Recvd: NO
- Subj: Re: SEARCH FUNCTION Conf: (36) C Language
- ---------------------------------------------------------------------------
- On 05-09-93 Mark Corgan wrote...
-
- MC> I will post my tree and search functions in the next message...
-
- Looking forward to it.
-
- MC> BG> The advantage to using a text file is that you can format it any way y
- ou
- MC> BG> want and then redirect it to the printer or text editor if you need to
- .
- MC>
- MC> That is exactly why I am maintaining the two different files.
-
- What I did in my program was to maintain one file and then
- "print" it to a file when I wanted it. There was less to
- maintain and I could change the output format if I wanted.
- I set the mode to "wb" and it would just overwrite the
- existing file.
-
- MC> I would be interested in SearchIndex. Is it small enough to post? As for B-
-
- MC> trees, I am just beginning to explore them. If I have any
- MC> exciting revelations, I will be sure to post them.
-
- ___------------------8<-------------------------
- #include <stdio.h>
- /*
- Disclaimer:
- This function is released to the public domain by the author,
- John Greep. The author cannot be held responsible for any
- loss or damages resulting from the use of this function, whether
- actual or inferred.
- */
- int SearchIndex (name,index,size,isize,pos,num,off,istore,store,search)
-
- char *name, /* Master File Name */
- *index; /* Index File Name */
- int size, /* Master File Record Size */
- isize, /* Index File Record Size */
- pos, /* Record Position to Search */
- num; /* Record number within file to begin search */
- long *off; /* Address of Index Record variable holding location */
- char *istore, /* Pointer to Index Record storage area */
- *store, /* Pointer to Master Record storage area */
- *search; /* Pointer to Search string */
- {
- char *temp, *stemp;
- FILE *fp, *ip;
-
- if ((fp = fopen(name,"rb"))==NULL) return 0;
- if ((ip = fopen(index,"rb"))==NULL) return 0;
- fseek (ip, (num - 1) * isize, SEEK_SET);
- while (fread (istore, isize, 1, ip))
- {
- fseek (fp, *off, SEEK_SET);
- fread (store,size,1,fp);
- stemp = store + pos -1;
- while (*stemp && *search)
- {
- temp = search;
- while ((*stemp|32)==(*temp|32)&&*temp)
- {
- stemp++;
- temp++;
- }
- if (!*temp)
- {
- temp--;
- stemp--;
-
- if ((*stemp|32)==(*temp|32))
- {
- fclose (fp);
- fclose (ip);
- return num;
- }
- }
- if ((*stemp|32) != (*search|32))
- stemp++;
- }
- num++;
- }
- fclose (fp);
- fclose (ip);
- return 0;
- }
- -----------------------8<-------------------------
-
- Not much different than the last function. It instead steps
- through the index and references the master file from there.
-
- MC> BG> Also, the size of your index can be just over 2000 records before you
- MC> BG> hit 64K. That's at 31 bytes per record.
- MC>
- MC> Yes. That is true. But I was speaking about static arrays.
- MC> Does this still hold true? I genereated the "DGROUP segment
- MC> exceeded" error when statically allocating more than 350
- MC> arrays. ???
-
- I'm not sure about static arrays. I suppose it would--- TBBS v2.1/NM
- * Origin: Autodesk Global Village (1:125/289)
- SEEN-BY: 1/211 11/2 4 13/13 101/1 108/89 109/25 110/69 114/5 123/19 124/1
- SEEN-BY: 153/752 154/40 77 157/2 159/100 125 575 950 203/23 209/209 261/1023
- SEEN-BY: 280/1 390/1 396/1 5 15 2270/1 2440/5 3603/20
-